﻿using System.Text.Json;
using Bdcs.Application;
using Bdcs.Core.Utils;
using Furion;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Bdcs.Web.Core
{
    [AppStartup(600)]
    public sealed class BdcsWebCoreStartup : AppStartup
    {

        // 配置应用所需服务，在该方法中可以添加应用所需要的功能或服务
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCorsAccessor();
            services.AddControllers()
                .AddUnifyResult<RespResult>()
                .AddJsonOptions(options =>
                {
                    options.JsonSerializerOptions.Converters.AddDateFormatString("yyyy-MM-dd HH:mm:ss");
                })
                .AddInject();
        }

        // 配置应用请求处理管道
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseCorsAccessor();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseInject(string.Empty);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}
